//
//  ProductlistModel.swift
//
//  Created by eme on 2017/1/3
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

class ProductlistModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kProductlistBrnameKey: String = "brname"
    internal let kProductlistPdnameKey: String = "pdname"
    internal let kProductlistBridKey: String = "brid"
    internal let kProductlistPdidKey: String = "pdid"
    internal let kProductlistImg1Key: String = "img1"
    internal let kProductlistMinshpriceKey: String = "minshprice"
    internal let kProductlistGrossprofitKey: String = "grossprofit"
    internal let kProductlistMunitKey: String = "munit"
    internal let kProductlistSalecountKey: String = "salecount"
    
    
    // MARK: 属性
    var brname: String
    var pdname: String
    var brid: String
    var pdid: Int
    var img1: String
    var minshprice: Double
    var grossprofit: Double
    var munit: String
    var salecount: Int
    var stock:Int
    var ptisproduct:String
    var pdstate:String!
    var bdprice:Double
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        brname = json[kProductlistBrnameKey].stringValue
        pdname = json[kProductlistPdnameKey].stringValue
        brid = json[kProductlistBridKey].stringValue
        pdid = json[kProductlistPdidKey].intValue
        img1 = json[kProductlistImg1Key].stringValue
        minshprice = json[kProductlistMinshpriceKey].doubleValue
        grossprofit = json[kProductlistGrossprofitKey].doubleValue
        munit = json[kProductlistMunitKey].stringValue
        salecount = json[kProductlistSalecountKey].intValue
        stock = json["stock"].intValue
        ptisproduct = json["ptisproduct"].stringValue
        pdstate = json["pdstate"].stringValue
        bdprice = json["bdprice"].doubleValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(brname as AnyObject, forKey: kProductlistBrnameKey)
        
        
        dictionary.updateValue(pdname as AnyObject, forKey: kProductlistPdnameKey)
        
        
        dictionary.updateValue(brid as AnyObject, forKey: kProductlistBridKey)
        
        
        dictionary.updateValue(pdid as AnyObject, forKey: kProductlistPdidKey)
        
        
        dictionary.updateValue(img1 as AnyObject, forKey: kProductlistImg1Key)
        
        
        dictionary.updateValue(minshprice as AnyObject, forKey: kProductlistMinshpriceKey)
        
        
        dictionary.updateValue(grossprofit as AnyObject, forKey: kProductlistGrossprofitKey)
        
        
        dictionary.updateValue(munit as AnyObject, forKey: kProductlistMunitKey)
        
        
        dictionary.updateValue(salecount as AnyObject, forKey: kProductlistSalecountKey)
        
        
        return dictionary
    }
    
    
}
